const encryption = require("../Models/encryption");
const Admin = require("../Models/admin");

// 去数据库 admins 查询 adminname 是否存在
exports.adminInit = Admin.find({adminName: "admin"})
    .then(data => {
        if (data.length === 0){
            console.log(data);
            // 管理员不存在，创建管理员
            new Admin({
                adminName: "admin",
                password: encryption("admin"),
                role: 666
            }, false)
            .save()
            .then(data => {
                console.log(data);
            })
            .catch(err => {
                console.log(err);
            })
        }else {
            console.log("管理员已存在");
        }
    });